package com.xjtu.chapter07.component;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/20 22:02
 */
public class DialogDemo {
    public static void main(String[] args) {
        Frame frame=new Frame("测试Dialog");

        //创建两个对话框Dialog对象，一个模式的，一个非模式的
        Dialog d1 = new Dialog(frame,"模式对话框",true);
        Dialog d2 = new Dialog(frame,"非模式对话框",false);
        d1.setBounds(20,30,300,200);
        d2.setBounds(20,30,300,200);

        Button b1 = new Button("打开模式对话框");
        Button b2 = new Button("打开非模式对话框");

        //给b1和b2绑定监听事件
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d1.setVisible(true);
            }
        });
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d2.setVisible(true);
            }
        });

        frame.add(b1,BorderLayout.NORTH);
        frame.add(b2);
        frame.pack();
        frame.setVisible(true);

    }
}
